<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="/mdui/css/mdui.min.css">
    <script defer src="/mdui/js/mdui.min.js"></script>
    <script src="/js/axios.min.js"></script>
    <script src="/js/qs.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/vue.js"></script>


</head>
<body class="mdui-theme-primary-indigo mdui-theme-accent-pink">


<div class="mdui-container-fluid" id="app">

    <h1 class="mdui-text-color-theme">新增用户</h1>
    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">用户名</label>
        <input class=" mdui-textfield-input" type="text" v-model="user.name"/>
    </div>
    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">登录名</label>
        <input class="mdui-textfield-input" type="text" v-model="user.loginName"/>
    </div>
    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">性别</label>
        &nbsp;&nbsp;&nbsp;
        <div class="mdui-textfield-input">
            <input type="radio" value="1" v-model="user.gender">女
            <input type="radio" value="0" v-model="user.gender">男
        </div>
        <!--        <select v-model="user.gender" class="mdui-textfield-input">-->
        <!--            <option value="0">女</option>-->
        <!--            <option value="1">男</option>-->
        <!--        </select>-->
    </div>

    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">生日</label>
        <input class="mdui-textfield-input" type="date" v-model="user.birthday"/>
    </div>

    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">邮箱</label>
        <input class="mdui-textfield-input" type="email" v-model="user.email"/>
    </div>

    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">电话</label>
        <input class="mdui-textfield-input" type="text" v-model="user.phone"/>
    </div>

    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">lock</i>
        <label class="mdui-textfield-label">状态</label>

        <select v-model="user.disabled" class="mdui-textfield-input" type="text">
            <option value="false">启用</option>
            <option value="true">禁用</option>
        </select>
    </div>

    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">部门</label>
        <select class="mdui-select mdui-textfield-input" v-model="user.dId">
            <option v-for="d in departments " :value="d.id">{{d.dname}}</option>
        </select>
    </div>

    <div style="text-align: center">
        <button @click="adduser" class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-green-800">新增</button>
        <a href="list.html" class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-green-800">返回</a>
    </div>

</div>

<script>
    new Vue({
        el: '#app',
        data: {
            users: [],
            departments: [],
            user: {
                name: "",
                loginName: "",
                gender: 0,
                birthday: "",
                email: "",
                dId: '',
                phone: "",
                disabled: false,

            }
        },
        created() {

            this.findList();
        },
        methods: {

            findList() {
                let _this = this
                axios.get("/depaerment/list")
                    .then(function (res) {
                        _this.departments = res.data;
                    })
            },
            adduser() {
                if (this.user.name == "") {
                    mdui.alert("请输入姓名")
                    return;
                }
                console.log(this.user)
                let _this = this;

                axios.post("/user/addUser", this.user)

                    .then(function (res) {
                        if (res.data.success) {
                            mdui.alert("新增成功");
                            _this.user = {
                                name: "",
                                loginName: "",
                                gender: 0,
                                birthday: "",
                                email: "",
                                phone: "",
                                dId: '',
                                disabled: 0
                            }
                        }

                    })
            },
        }
    })

</script>


</body>
</html>